package com.servicesystem.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.mike.module.core.utils.CommonUtil;
import com.mike.module.core.utils.ComponentUtil;
import com.servicesystem.demo.entity.ServiceData;
import com.servicesystem.demo.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName CommonController
 * @Description TODO
 * @Author Mike
 * @Date 2019/6/18 11:18
 * @Version 1.0
 */
@CrossOrigin
@RestController
@RequestMapping("/api")
public class CommonController {

    private final SystemService systemService;
    private final ComponentUtil componentUtil;

    @Autowired
    public CommonController(SystemService systemService, ComponentUtil componentUtil) {
        this.systemService = systemService;
        this.componentUtil = componentUtil;
    }

    @PostMapping("/system")
    public JSONObject serviceSystem(@RequestBody ServiceData serviceData){
        serviceData.getHead().setHostName((String) componentUtil.getProperties("mike.service.host.name"));
        serviceData.setGetServiceNameSql((String) componentUtil.getProperties("mike.parse.xml.sql.getServiceName"));
        serviceData.getHead().setPath("system");
        System.out.println(serviceData);
        return systemService.entrance(serviceData);

    }
}
